#ifndef __BUOLA_GUI_CMENU_H__
#define __BUOLA_GUI_CMENU_H__

#include <buola/gui/cmenuitem.h>

namespace buola { namespace gui {

///\addtogroup gui
///@{

////////////////////////////////////////////////////////////////////////////

/// menu

/// contains a list of menu items, for showing them in a menu or a tool bar
///
////////////////////////////////////////////////////////////////////////////

class CMenu : public UShared
{
public:
///! \name constructor and destructor
//@{
    CMenu();
    ~CMenu();
//@}

    //! get the i-th item in the menu
    PMenuItem Get(int i);
    //! returns the number of items
    int size();

    //! adds a new item, and returns it
    PMenuItem Add(PMenuItem pItem);

    //! adds a title to the menu
    void AddTitle(const std::wstring&,PIcon=nullptr);

    //! adds a submenu item
    PMenu AddSubMenu(const std::wstring&,PIcon=nullptr,PMenu=nullptr,
                     const std::wstring &pComment=std::wstring());

    //! adds an inline menu
    void AddInlineMenu(PMenu=nullptr);

    //! adds a separator item
    void AddSeparator();

    //! adds a window item
    void AddWindow(const PWindow &pWindow);

    //! removes all items
    void RemoveAll();
    //! removes item by ID
    void RemoveItem(PMenuItem pItem);
    
    void FillWith(os::CAppMenu *pMenu);

    void OnItemChanged();
    
    //! callback for when an inline menu changed
    void OnInlineMenuChanged();

public:
    //! triggered when the menu should be filled
    USignal<void(PMenu)> sFillMenu;
    //! triggered when the menu changed
    USignal<void()> sChanged;

private:
    std::vector<PMenuItem> mItems; //!< all items in the menu
    bool mOpenFirstTime;            //!< whether the menu has been shown
    int mCachedCount;               //!< number of items
};

///@}

/*namespace gui*/ } /*namespace buola*/ }

#endif
